package org.tarena.dang.util;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class EmailUtils {
	public static int sendEmail(String emailAddr,	String code){
		SimpleEmail email = new SimpleEmail();
		email.setHostName("smtp.sina.com");
		email.setAuthentication("zhubo612", "719612");
		email.setCharset("UTF-8");
		try {
			email.addTo(emailAddr);
			email.setFrom("zhubo612@sina.com");//必须和Authentication使用的用户相同，否则失败
			email.setSubject("当当邮箱验证");
			email.setMsg("验证码："+code);
			email.send();
			System.out.println("给"+emailAddr+"发送了邮箱验证码");
			System.out.println("验证码为:"+code);
			return Constant.EXECUTE_OK;
		} catch (EmailException e) {
			e.printStackTrace();
			return Constant.EXECUTE_FAIL;
		}
	}
}
